package com.gxa.controller.SystemController;

import com.gxa.entity.Professional;
import com.gxa.entity.Role;
import com.gxa.service.system.ProfessionalService;
import com.gxa.utils.R;
import com.gxa.vo.ProfessionalVo;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Api(tags = "职称管理模块")
@RestController
public class ProfessionalController {

    @Autowired
    private ProfessionalService professionalService;


    @ApiOperation(value="Professional列表接口",notes="查询全部职称信息",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回所有的职称详细信息",examples = @io.swagger.annotations.Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("prof:sel")
    @GetMapping("/prof/qureyAllProfessional")
    public R queryAllProfessional(){
        List<ProfessionalVo> professionalVos = professionalService.queryAllPro();
        return R.ok().put("data",professionalVos);
    }

    @ApiOperation(value="Professional查询接口",notes="根据输入内容查询职称信息",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回所有的职称详细信息",examples = @io.swagger.annotations.Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("prof:sel")
    @PostMapping("/prof/qureyProfessionals")
    public R queryProfessionals(@ApiParam(name="professional",value = "职称名参数--这里输入要查询的职称名",required = true)@RequestBody ProfessionalVo professional){
        System.out.println(professional.getName());
        List<ProfessionalVo> professionalVos = professionalService.queryProByName("%"+professional.getName()+"%");
        return R.ok().put("data",professionalVos);

    }

    @ApiOperation(value="Professional增加接口",notes="增加职称接口",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回增加是否成功",examples = @io.swagger.annotations.Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("prof:add")
    @PostMapping("/prof/addProfessional")
    public R addProfessional(@ApiParam(name="professional",value = "职称参数--这里写输入的角色信息描述",required = true)@RequestBody ProfessionalVo professional){
        System.out.println(professional);
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
        professional.setTime(sdf.format(new Date()));
        professionalService.addProf(professional);
        return R.ok();
    }

    @ApiOperation(value="进入编辑Professional接口",notes="进入操作列编辑职称操作接口",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "根据职称id查询到的职称详细信息",examples = @io.swagger.annotations.Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("prof:sel")
    @PostMapping("/prof/preEditProfessional")
    public R preEditProfessional(@ApiParam(name="professional",value = "职称id",required = true)@RequestBody ProfessionalVo professional){
        System.out.println(professional.getId());
        ProfessionalVo professionalVo = professionalService.queryProfById(professional.getId());
        return R.ok().put("data",professionalVo);
    }

    @ApiOperation(value="编辑Professional接口",notes="编辑职称操作接口",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回编辑是否成功",examples = @io.swagger.annotations.Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("prof:update")
    @PostMapping("/prof/editProfessional")
    public R editProfessional(@ApiParam(name="professional",value = "职称参数--这里写输入的职称信息描述,注意时间为进入修改接口查到的时间",required = true)@RequestBody ProfessionalVo professional){
        System.out.println(professional);
        professionalService.updateProf(professional);
        return R.ok();
    }

    @ApiOperation(value="删除Professional接口",notes="删除职称操作接口",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回删除是否成功",examples = @io.swagger.annotations.Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("prof:del")
    @DeleteMapping("/prof/delProfessional")
    public R delProfessional(@ApiParam(name="professional",value = "职称id",required = true)@RequestBody ProfessionalVo professional){
        System.out.println(professional.getId());
        professionalService.delProfById(professional.getId());
        return R.ok();
    }

    @ApiOperation(value="修改Professional状态接口",notes="修改职称状态操作接口",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回修改是否成功",examples = @io.swagger.annotations.Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("prof:update")
    @PutMapping("/prof/editProfessionalStatus")
    public R editProfessionalStatus(@ApiParam(name="professional",value = "点击状态后的职称详细信息，注意：只传当前职称的id，和改变后的状态",required = true)@RequestBody ProfessionalVo professional){
        System.out.println(professional);
        professionalService.updateProfStatus(professional.getId(),professional.getStatus());
        return R.ok();
    }
}
